<template>
  <div>
    <div class="pageTitleWhole">
      <a-breadcrumb>
        <a-breadcrumb-item>每日油耗统计</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <div class="pageContentWhole">
      <a-row>
        <a-col :span="24">
          <a-form layout="inline">
            <a-form-item label="日期">
              <a-range-picker @change="onChangeTime">
                <a-icon slot="suffixIcon" type="calendar" />
              </a-range-picker>
            </a-form-item>

            <a-form-item>
              <a-button type="primary" @click="handleSubmit1">查询</a-button>
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="exportExcel">导出excel</a-button>
            </a-form-item>
          </a-form>

          <a-tabs @change="tabChange" :tab-bar-style="{margin:'20px 0 0 0',padding:'0'}">
            <a-tab-pane :key="1" tab="油库消耗" style="padding:0"></a-tab-pane>
            <a-tab-pane :key="2" tab="加油卡消耗" style="padding:0"></a-tab-pane>
          </a-tabs>
          <a-table
            :columns="columns"
            :data-source="tableData"
            :pagination="pagination"
            :loading="loading"
            :row-key="(record,index) => index"
          >
            <template slot="rn" slot-scope="text, record, index">{{index + 1}}</template>
          </a-table>
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
import { commonExport } from '@/api/request'
import { queryTruckOilStatisticsList } from '@/api/landCenter'

let queryColumn = null

export default {
  data () {
    // 油库
    const column1 = [
      {
        title: '序号',
        dataIndex: '',
        width: 60,
        scopedSlots: { customRender: 'rn' }
      },
      {
        title: '累计采购油量(吨)',
        dataIndex: 'purchaseOil'
      },
      {
        title: '累计加油量(吨)',
        dataIndex: 'inOil'
      },
      {
        title: '油库余油量(吨)',
        dataIndex: 'remainingOil'
      },
      {
        title: '单日耗油量(吨)',
        dataIndex: 'outOil'
      },
      {
        title: '车内余油量(吨)',
        dataIndex: 'truckRemainingOil'
      },
      {
        title: '日期',
        dataIndex: 'statisticsDate'
      }
    ]
    // 加油卡
    const column2 = [
      {
        title: '序号',
        width: 60,
        scopedSlots: { customRender: 'rn' }
      },
      {
        title: '累计采购金额(元)',
        dataIndex: 'purchaseAmount'
      },
      {
        title: '累计充值金额(元)',
        dataIndex: 'rechargeAmount'
      },
      {
        title: '加油卡消费金额(元)',
        dataIndex: 'cardSpendAmount'
      },
      {
        title: '加油卡余额(元)',
        dataIndex: 'cardRemainingAmount'
      },
      {
        title: '单日耗油量(吨)',
        dataIndex: 'outOil'
      },
      {
        title: '车内余油量(吨)',
        dataIndex: 'truckRemainingOil'
      },
      {
        title: '日期',
        dataIndex: 'statisticsDate'
      }
    ]

    queryColumn = [column1, column2]

    return {
      searchForm: {
        type: 1, // 1油库消耗 2加油卡消耗
        time1: null, // 日期
        time2: null // 日期
      },
      columns: queryColumn[0],
      loading: false,
      tableData: [],
      pagination: {},
      pageNum: 1,
      pageSize: 10
    }
  },
  methods: {
    onChangeTime (data, dateString) {
      this.searchForm.time1 = dateString[0]
      this.searchForm.time2 = dateString[1]
    },
    tabChange (i) {
      this.searchForm.type = i
      this.columns = queryColumn[i - 1]
      this.handleSubmit1()
    },
    handleSubmit1 () {
      this.pageNum = 1
      this.handleSubmit()
    },
    handleSubmit () {
      this.loading = true
      queryTruckOilStatisticsList({
        ...this.searchForm,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }).then(rsp => {
        this.loading = false
        this.tableData = rsp.data.list
        this.pagination = {
          current: this.pageNum,
          pageSize: rsp.data.pageSize,
          total: rsp.data.total,
          showQuickJumper: false,
          showSizeChanger: true,
          showTotal: total => `共${total}条记录 第${this.pageNum}/${rsp.data.pages}页`,
          onChange: pageNum => {
            this.pageNum = pageNum
            this.handleSubmit()
          },
          onShowSizeChange: (current, size) => {
            this.pageNum = current
            this.pageSize = size
            this.handleSubmit()
          }
        }
      }).catch(() => { this.loading = false })
    },
    exportExcel () {
      commonExport('/truckStock/exportTruckOilStatisticsList', {
        ...this.searchForm,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        columns: queryColumn[this.searchForm.type - 1]
      })
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.handleSubmit()
    })
  }
}
</script>

<style lang="less" scoped>
</style>
